#ifndef _FCLISTVIEW_CTRL_H
#define _FCLISTVIEW_CTRL_H

#ifdef WIN32_PLATFORM_PSPC
class CFCHeaderCtrl : public CWindowImpl<CFCHeaderCtrl, CHeaderCtrl>
{
public:
	BEGIN_MSG_MAP(CFCHeaderCtrl)
		MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
		MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
		MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
	END_MSG_MAP()
		
	LRESULT OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
	{
		m_hdti.pt.x = LOWORD(lParam);
		m_hdti.pt.y = HIWORD(lParam);
		HitTest(&m_hdti);

		if ( m_hdti.flags != HHT_ONHEADER )
		{
			m_bCapture = TRUE;
			SetCapture();
		}
		else
		{
			m_bCapture = FALSE;
		}

		return 0L;
	}

	LRESULT OnLButtonUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
	{
		if ( m_bCapture )
		{
			HWND hwndList = GetParent();
			if ( hwndList )
			{
				::InvalidateRect(hwndList, NULL, TRUE);
			}

			ReleaseCapture();
			m_bCapture = FALSE;
		}
		else
		{
			bHandled = FALSE;
		}

		return 0L;
	}

	LRESULT OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
	{
		if ( !m_bCapture )
		{
			bHandled = FALSE;
		}
		else
		{
			HWND hwndList = GetParent();
			
			if ( hwndList && (m_hdti.iItem>=0) )
			{
				//Set item new width
				HDITEM hdi = {0};
				hdi.mask = HDI_WIDTH;
				GetItem(m_hdti.iItem, &hdi);
				
				hdi.cxy = hdi.cxy + LOWORD(lParam) - m_hdti.pt.x;
				SetItem(m_hdti.iItem, &hdi);
				m_hdti.pt.x = LOWORD(lParam);

				RECT rcList = {0};
				::GetWindowRect(hwndList, &rcList);
 				::InvalidateRect(hwndList, NULL, TRUE);

				CPaintDC dc(hwndList);
				POINT pt = {0};
				pt.x = LOWORD(lParam);
				
				dc.MoveTo(pt);
				pt.y = rcList.bottom;
				dc.LineTo(pt);
			}
		}
		
		return 0L;
	}


private:
	BOOL m_bCapture;
	HDHITTESTINFO m_hdti;
};


class CFCListViewCtrl : public CWindowImpl<CFCListViewCtrl, CListViewCtrl>
{	
public:
	BEGIN_MSG_MAP(CFCListViewCtrl)
	END_MSG_MAP()

public:
	BOOL SubclassWindow(HWND hWnd)
	{
		BOOL bRet = CWindowImpl<CFCListViewCtrl, CListViewCtrl>::SubclassWindow(hWnd);
		
		if ( bRet )
		{
			bRet = InitHeaderCtrl();
		}
		
		return bRet;
	}
	
private:
	BOOL InitHeaderCtrl(void)
	{
		BOOL bRet = FALSE;
		CHeaderCtrl header = this->GetHeader();

		if ( header.m_hWnd )
		{
			m_header.SubclassWindow(header.m_hWnd);
			bRet = TRUE;
		}

		return bRet;
	}

private:
	CFCHeaderCtrl m_header;
};

#elif defined(WIN32_PLATFORM_WFSP)
class CFCListViewCtrl : public CWindowImpl<CFCListViewCtrl, CListViewCtrl>
{	
public:
	BEGIN_MSG_MAP(CFCListViewCtrl)
		MESSAGE_HANDLER(WM_GETDLGCODE, OnGetDlgCode)
	END_MSG_MAP()		
		
	LRESULT OnGetDlgCode(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
	{
		return DLGC_WANTMESSAGE;		
	}
};
#endif //#elif defined(WIN32_PLATFORM_WFSP)

#endif